package com.ss.project.xia17user;

import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;

/**
 * 启动类
 * 夏十七用户中心
 * @author xia17
 * @since 2020-09-11 17:54
 */
@SpringBootApplication
@MapperScan("com.ss.project.xia17user.dao.mapper")
public class Xia17userApplication {

    /**
     * 启动类
     * @param args 启动参数
     */
    public static void main(String[] args) {
        SpringApplication.run(Xia17userApplication.class, args);
    }


    /**
     * 添加参数检验  ,
     * 只有添加了这个类才可以在参数中直接使用  @NotNull String test , 并且需要在Controller类上加上注解 @Validated
     * @return MethodValidationPostProcessor
     */
    @Bean
    public MethodValidationPostProcessor methodValidationPostProcessor() {
        return new MethodValidationPostProcessor();
    }


    /**
     * 解决JS Long精度丢失问题
     * @return /
     */
    @Bean("jackson2ObjectMapperBuilderCustomizer")
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder
                .serializerByType(Long.class, ToStringSerializer.instance)
                .serializerByType(Long.TYPE, ToStringSerializer.instance);
    }




}
